﻿

@model PagedList<ADZ_LabelConfig>
@{
    ViewBag.Title = "板块列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

}

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:65px">ID</th>
            <th>名称</th>
            <th>是否展示</th>
            <th>所属类别</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    @m.label_type
                </td>
                <td style="padding:5px 0 0 2px;">
                    @m.label_name
                </td>
                <td>
                    @switch (m.is_show)
                    {
                        case 1:
                            @:<div class="green">展示</div>
                            break;
                        default:
                            @:<div class="red">不展示</div>
                            break;
                    }
                </td>
                <td>
                    @m.base_label_name
                </td>
                <td>
                    <a class="up @(index == 1 ? "gray" : "") " href="javascript:void()" onclick="moveup(@m.label_type)">上移</a> <a class="down @(index == (Model.Count) ? "gray" : "")" href="javascript:void()" onclick="movedown(@m.label_type)">下移</a>
                    <a href="@Url.Action("labelinfo", "product", new { id = m.label_type})">查看详情</a>

                </td>
            </tr>
        }
    }
</table>

<script>
    reloadHandler = function () {
        window.location.reload();
    }
    function moveup(label_type) {
        handleSort(label_type, 1);
    }
    function movedown(label_type) {
        handleSort(label_type, -1);
    }
    //处理用户点击上移和下移
    // -1 下移  1上移
    function handleSort(label_type, sort_type) {
        $.ajax({
            url: "/product/UpdateLabelSort",
            type: "post",
            dataType: "json",
            data: {
                label_type: label_type,
                sort_type: sort_type
            },
            success: function (result) {
                if (result.IsSuccess) {
                    ShowActionResult(result, reloadHandler);
                }
                else {
                    BUI.Message.Alert(result.Message, 'error');

                }
            }
        })
    }
</script>